import http from './interface'

/**
 * 将业务所有接口统一起来便于维护
 * 如果项目很大可以将 url 独立成文件，接口分成不同的模块
 * 
 */

// 单独导出(测试接口) import {test} from '@/common/vmeitime-http/'
export const test = (data) => {
	/* http.config.baseUrl = "http://localhost:8080/api/"
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
		}
	} */
	//设置请求结束后拦截器
	http.interceptor.response = (response) => {
		console.log('个性化response....')
		//判断返回状态 执行相应操作
		return response;
	}
	return http.request({
		baseUrl: 'https://unidemo.dcloud.net.cn/',
		url: 'ajax/echo/text?name=uni-app',
		dataType: 'text',
		data,
	})
}


// 获取文章列表
export const getArticle = (data) => {
	let appId = uni.getStorageSync('appId') || ''
	return http.request({
		url: '/program/list_page',
		method: 'GET',
		data: {
			...data,
		},
		// handle:true
	})
}

// 获取标签列表
export const getTags = (data) => {
	let appId = uni.getStorageSync('appId') || ''
	return http.request({
		url: '/program/tag',
		method: 'GET',
		data: {
			...data,
			appId
		},
		// handle:true
	})
}

export const getTops = (data) => {
	let appId = uni.getStorageSync('appId') || ''
	return http.request({
		url: '/program/slider',
		method: 'GET',
		data: {
			...data,
			appId
		},
		// handle:true
	})
}


// 获取文章详情
export const getArticleDetail = ({
	id,
	fromId = ''
}) => {
	let appId = uni.getStorageSync('appId') || ''
	let openid = uni.getStorageSync('openid') || ''
	return http.request({
		url: `/program/content?id=${id}&openid=${openid}&appId=${appId}`,
		method: 'GET',
		// handle:true
	})
}

// 轮播图
export const banner = (data) => {
	let appId = uni.getStorageSync('appId') || ''
	return http.request({
		url: '/banner/36kr',
		method: 'GET',
		data: {
			...data,
			appId
		},
		// handle:true
	})
}

export const mpLogin = (data) => {
	let appId = uni.getStorageSync('appId') || ''
	return http.request({
		url: '/program/user/login',
		header: {
			'Content-Type': 'application/json;charset=UTF-8',
		},
		method: 'POST',
		data: {
			...data,
			appId
		},
	})
}

export const mpAction = (data) => {
	let appId = uni.getStorageSync('appId') || ''
	let openid = uni.getStorageSync('openid') || ''
	return http.request({
		url: '/program/user/action',
		header: {
			'Content-Type': 'application/json;charset=UTF-8',
		},
		method: 'PUT',
		data: {
			...data,
			appId,
			openid
		},
		// handle:true
	})
}

// 默认全部导出  import api from '@/common/vmeitime-http/'
export default {
	test,
	banner,
	getArticle,
	getTags,
	getTops,
	mpLogin,
	mpAction,
	getArticleDetail
}